<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
  >
    <ex-zbid-opening-arrange-form
      ref="realForm"
      :project="project"
      :sectionList="sectionList"
      @ok="submitCallback"
      :disabled="disableSubmit"
    />
  </j-modal>
</template>

<script>
import ExZbidOpeningArrangeForm from './ExZbidOpeningArrangeForm.vue'
import { getAction } from '@api/manage'

export default {
  name: 'ExZbidOpeningArrangeModal',
  components: {
    ExZbidOpeningArrangeForm,
  },
  data() {
    return {
      title: '场地预约',
      width: 800,
      visible: false,
      disableSubmit: false,
      // 标段列表
      sectionList: [],
      project: {},
      url: {
        queryProjectDetail: '/exProject/exProject/queryById',
      },
    }
  },
  methods: {
    // showModal(project, projectId) {
    //   this.visible = true
    //   this.getProjectDetail(projectId)
    //   projectId = projectId ? projectId : project.projectId
    //   this.querySectionListByProjectId(projectId)
    //   this.$nextTick(() => {
    //     this.$refs.realForm.add()
    //   })
    // },
    getProjectDetail(projectId) {
      getAction(this.url.queryProjectDetail, { id: projectId }).then((res) => {
        if (res.success) {
          var record = res.result
          this.project = record
        }
      })
    },
    async querySectionListByProjectId(mainId) {
      getAction('/exProject/exProject/queryExSectionByMainId', { id: mainId })
        .then((res) => {
          this.sectionList = res.result
        })
        .finally(() => {})
    },
    add(project, projectId) {
      this.visible = true
      this.getProjectDetail(projectId)
      projectId = projectId ? projectId : project.projectId
      this.querySectionListByProjectId(projectId)
      this.$nextTick(() => {
        this.$refs.realForm.add()
      })
    },
    edit(record) {
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
        this.getProjectDetail(record.projectId)
        this.querySectionListByProjectId(record.projectId)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.handleOk()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style scoped>
</style>
